﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Mechanics.GameEventMechanics {
    import Mechanics.*;
    import Classes.*;

    public class MallStorageMechanic extends GatedStorageMechanic {

        override protected function handlePlaceFromStorage(_arg1:Array):MechanicActionResult{
            var _local4:Object;
            var _local5:Array;
            var _local6:String;
            var _local7:int;
            var _local8:int;
            var _local9:int;
            var _local10:Array;
            var _local11:MapResource;
            var _local12:int;
            var _local13:Number;
            var _local2:MapResource = _arg1["mapResource"];
            var _local3:MechanicActionResult = super.handlePlaceFromStorage(_arg1);
            if (_local3.actionSuccess){
                _local4 = m_owner.getDataForMechanic("harvestState");
                if (((_local4) && (_local4["resources"]))){
                    _local5 = (_local4["resources"] as Array);
                    _local6 = _local2.getItemName();
                    _local7 = 0;
                    _local8 = -1;
                    _local9 = 0;
                    _local10 = m_owner.getDataForMechanic(m_config.type);
                    for each (_local11 in _local10) {
                        if (_local11.getItemName() == _local6){
                            _local9++;
                        };
                    };
                    _local12 = 0;
                    while (_local12 < _local5.length) {
                        if (_local6 == _local5[_local12]){
                            _local7++;
                            _local8 = _local12;
                        };
                        _local12++;
                    };
                    if (_local7 > _local9){
                        _local5.splice(_local8, 1);
                        _local4["resources"] = _local5;
                        _local13 = _local2.getItem().commodityReq;
                        _local4["customersReq"] = (Number(_local4["customersReq"]) - _local13);
                        if (_local4["customersReq"] <= 0){
                            _local4 = null;
                        };
                        m_owner.setDataForMechanic("harvestState", _local4);
                        (m_owner as IMerchant).updatePeepSpawning();
                    };
                };
            };
            return (_local3);
        }

    }
}//package Mechanics.GameEventMechanics 
